import { ProForm, ProFormDigit, ProFormText, ProFormTextArea } from "@ant-design/pro-components"
import { checkDictDataValueUnique } from '@/api/system/dict/data'
const DictDataForm = ({ dataId, dictType }) => {
  const checkDictValue = async (_, value) => {
    const msg = '数据字典值已存在'
    if (value === '') {
      return Promise.resolve()
    } else {
      const checkData = {
        dictValue: value,
        dictType: dictType,
        id: dataId !== undefined ? dataId : ''
      }
      let response = await checkDictDataValueUnique(checkData)
      if (response.data.code === '1') {
        return Promise.resolve()
      } else {
        return Promise.reject(msg)
      }
    }
  }
  return <>
    <ProForm.Group rowProps={{
      gutter: 20
    }}>

      <ProForm.Item name='id' hidden></ProForm.Item>
      <ProForm.Item name='version' hidden></ProForm.Item>
      <ProForm.Item name='status' hidden></ProForm.Item>

      <ProFormText
        colProps={{ lg: 12, md: 12, sm: 24 }}
        name="dictType"
        label="字典类型"
        placeholder="请输入字典类型"
        rules={[{ required: true, message: '请输入字典类型' }]}
        disabled
      />

      <ProFormText
        colProps={{ lg: 12, md: 12, sm: 24 }}
        name="dictLabel"
        label="字典名称"
        placeholder="请输入字典名称"
        rules={[{ required: true, message: '请输入字典名称' }]}
      />

      <ProFormText
        colProps={{ lg: 12, md: 12, sm: 24 }}
        name="dictValue"
        label="数据键值"
        placeholder="请输入数据键值"
        rules={[{ required: true, message: '请输入数据键值' }, { validator: checkDictValue, validateTrigger: 'onBlur' }]}
      />

      <ProFormDigit
        colProps={{ lg: 12, md: 12, sm: 24 }}
        name="dictSort"
        label="字典排序"
        min={0}
      />

    </ProForm.Group>
    <ProFormTextArea
      rows={4}
      name="remark"
      label="描述"
      placeholder="请输入内容"
    />
  </>
}



export default DictDataForm